package com.smartwebx.ha.web.admin.module.screen.area;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.citrus.turbine.dataresolver.Param;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.smartwebx.ha.biz.assign.HaAreaManager;
import com.smartwebx.ha.dal.assign.bean.HaArea;
import com.smartwebx.ha.dal.bean.AreaAndGroup;

public class AjaxAddArea {
	@Autowired
	private HaAreaManager haAreaManager;

	public void execute(@Param("data")String data) throws Exception {
		ObjectMapper mapper = new ObjectMapper();
		mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,
				false);
		AreaAndGroup areaAndGroup=mapper.readValue(data, AreaAndGroup.class);
		HaArea area= new HaArea();
		BeanUtils.copyProperties(areaAndGroup,area);
		area.setCenterPoint(areaAndGroup.getLongitude()+","+areaAndGroup.getLatitude());
		if (area.getId() == null) {
			haAreaManager.addArea(area);
		} else {
			haAreaManager.updateArea(area);
		}
	}
}
